namespace TO3.Models.Context1
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Locations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Matches",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TournamentId = c.Int(nullable: false),
                        Player1Id = c.Int(nullable: false),
                        Player2Id = c.Int(nullable: false),
                        TableId = c.Int(nullable: false),
                        Round = c.Int(nullable: false),
                        Player1CP = c.Int(nullable: false),
                        Player2CP = c.Int(nullable: false),
                        WinnerId = c.Int(),
                        Player_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Players", t => t.Player_Id)
                .ForeignKey("dbo.Tournaments", t => t.TournamentId, cascadeDelete: true)
                .ForeignKey("dbo.Players", t => t.Player1Id, cascadeDelete: false)
                .ForeignKey("dbo.Players", t => t.Player2Id, cascadeDelete: false)
                .ForeignKey("dbo.Players", t => t.WinnerId)
                .Index(t => t.Player_Id)
                .Index(t => t.TournamentId)
                .Index(t => t.Player1Id)
                .Index(t => t.Player2Id)
                .Index(t => t.WinnerId);
            
            CreateTable(
                "dbo.Players",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        LocationId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Locations", t => t.LocationId, cascadeDelete: true)
                .Index(t => t.LocationId);
            
            CreateTable(
                "dbo.TournamentRegistrations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TournamentId = c.Int(nullable: false),
                        PlayerId = c.Int(nullable: false),
                        HasPaid = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Players", t => t.PlayerId, cascadeDelete: true)
                .ForeignKey("dbo.Tournaments", t => t.TournamentId, cascadeDelete: true)
                .Index(t => t.PlayerId)
                .Index(t => t.TournamentId);
            
            CreateTable(
                "dbo.Tournaments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ActiveRound = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Matches", "WinnerId", "dbo.Players");
            DropForeignKey("dbo.Matches", "Player2Id", "dbo.Players");
            DropForeignKey("dbo.Matches", "Player1Id", "dbo.Players");
            DropForeignKey("dbo.TournamentRegistrations", "TournamentId", "dbo.Tournaments");
            DropForeignKey("dbo.Matches", "TournamentId", "dbo.Tournaments");
            DropForeignKey("dbo.TournamentRegistrations", "PlayerId", "dbo.Players");
            DropForeignKey("dbo.Matches", "Player_Id", "dbo.Players");
            DropForeignKey("dbo.Players", "LocationId", "dbo.Locations");
            DropIndex("dbo.Matches", new[] { "WinnerId" });
            DropIndex("dbo.Matches", new[] { "Player2Id" });
            DropIndex("dbo.Matches", new[] { "Player1Id" });
            DropIndex("dbo.TournamentRegistrations", new[] { "TournamentId" });
            DropIndex("dbo.Matches", new[] { "TournamentId" });
            DropIndex("dbo.TournamentRegistrations", new[] { "PlayerId" });
            DropIndex("dbo.Matches", new[] { "Player_Id" });
            DropIndex("dbo.Players", new[] { "LocationId" });
            DropTable("dbo.Tournaments");
            DropTable("dbo.TournamentRegistrations");
            DropTable("dbo.Players");
            DropTable("dbo.Matches");
            DropTable("dbo.Locations");
        }
    }
}
